<%-- 
    Document   : index.jsp
    Created on : 13 déc. 2014, 10:30:00
    Author     : coload12
--%>

<%@page import="webapps.tools.Config"%>
<%@page import="webapps.servlet.AdminCompteController"%>
<%@page import="java.text.DecimalFormat"%>
<%@page import="java.text.NumberFormat"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="metier.pojo.Compte"%>
<%@page import="webapps.tools.Tools"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page import="metier.pojo.Client"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>JSP Page</title>
        <jsp:include page="<%= Config.emp_header%>"></jsp:include>
    </head>
    <body>
        <%
            Client leclient = (Client)request.getAttribute("client");
            if (leclient == null)
            {
                response.sendRedirect("AdminController");
            }
            NumberFormat formatter= new DecimalFormat("###,###,###.00 €"); 
            
        %>
        <h1>Liste des comptes du client : <%= leclient.getPrenom()%> <%= leclient.getNom() %> </h1>
        
        <ol class="breadcrumb">
            <li><a href="AdminController">Liste des utilisateurs</a></li>
            <li class="active"><%= leclient.getPrenom() + " " + leclient.getNom() %></li>
         </ol>
        <%
            Tools.displayMessage(request, out, AdminCompteController.message);
        %>

        <table class="table table-hover">
            <tr>
                <th>Numero</th>
                <th>Nom</th>
                <th class="montant" style="padding-right:3%;">Montant</th>
                <th>Tranférer</th>
                <th>Action</th>
            </tr>
            <%
                List<Compte> biblio = ((List<Compte>) request.getAttribute("comptes"));
                Iterator<Compte> it = biblio.iterator();
                float montant  = 0f;
                while (it.hasNext()) 
                {
                    Compte uncompte = it.next();
                    if (uncompte.getEtat() == Compte.COMPTE_ENABLED)
                    {
                        montant += uncompte.getMontant();
            %>
            <tr>
                <td><%= uncompte.getId()%></td>
                <td><%= uncompte.getNom()%></td>
                <td class="montant" style="padding-right:3%;"><%= formatter.format( uncompte.getMontant() )%></td>
                <td>
                    <form class="form-inline" role="form" method="post" action="?id=<%= leclient.getId() %>">
                        <input type="hidden" name="action" value="transfert" /> 
                        <input type="hidden" name="crediteur" value="<%= uncompte.getId() %>"/>
                        <div class="form-group">
                            <input name="montant" type="text" class="form-control" id="exampleInputPassword2" placeholder="Taper le montant">
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <select class="form-control" name="debiteur">
                                    <% 
                                        for (Compte ucompte : biblio)
                                        {
                                            if (ucompte.getId() != uncompte.getId() && ucompte.getEtat() == Compte.COMPTE_ENABLED)
                                            {
                                                out.println ("<option value='" + ucompte.getId()+ "'>" + ucompte.getNom() + "</option>");
                                            }
                                        }
                                    %>
                                  </select>
                            </div>
                        </div>
                        <button type="submit" class="btn btn-default">Transférer</button>
                    </form>
                </td>
                <td>
                    <a href="AdminVirementController?compte=<%= uncompte.getId()%>&id=<%= leclient.getId() %>">[consulter]</a>
                    <a href="?action=supprimer&compte=<%= uncompte.getId()%>&id=<%= leclient.getId() %>">[supprimer]</a>
                </td>
            </tr>
            <%
                    }
                }

            %>
            <tr>
                <th>Total</th>
                <th></th>
                <th class="montant" style="padding-right:3%;"><%= formatter.format(montant) %></th>
                <th></th>
                <th></th>
                <th></th>
            </tr>
        </table>
        <form class="form-inline" role="form" method="post" action="?id=<%= leclient.getId() %>">
            <input type="hidden" name="action" value="add" /> 
            <div class="form-group">
                <input name="nom" type="text" class="form-control" id="exampleInputPassword2" placeholder="nom">
            </div>
            <div class="form-group">
                <div class="input-group">
                    <input name="montant" type="text" class="form-control" id="exampleInputEmail2" placeholder="montant">
                </div>
            </div>
            <button type="submit" class="btn btn-default">Ajouter un compte</button>
        </form>
    </body>
</html>
